const DiscussService = require("../sercice/DiscussServuce")


const DiscussControl = {
    addDiscuss: async (req, res) => {
        try {
            const result = await DiscussService.add_discuss(req.body)
            res.status(200).send({
                msg: "添加成功",
                code: 200
            })

        } catch (error) {
            res.status(411).send({
                msg: "添加失败",
                code: 411
            })
        }
    },
    find_discuss: async (req, res) => {
        try {
            const result = await DiscussService.find_discuss(req.params.id)
            res.status(200).send({
                msg: "获取成功",
                data: result,
                code: 200
            })

        } catch (error) {

            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })
        }
    },
    discuss_back: async (req, res) => {
        try {
            const result = await DiscussService.find_discuss_back(Number(req.params.skp), req.params.types)
            res.status(200).send({
                msg: "获取成功",
                data: result[0],
                code: 200
            })

        } catch (error) {
            console.log(error)
            res.status(411).send({
                msg: "获取失败",
                data: [],
                code: 411
            })

        }
    },
    delete_one: async (req, res) => {
        try {
            const result = await DiscussService.deleteone(req.params.id)
            console.log(result, '?')
            res.status(200).send({
                msg: "删除成功",
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "删除失败",
                code: 411
            })
        }
    }

}

module.exports = DiscussControl